package com.ruoyi.web.controller.salon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SalonService;
import com.ruoyi.system.service.ISalonServiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务管理Controller
 *
 * @author 23
 * @date 2022-03-30
 */
@RestController
@RequestMapping("/system/service")
public class SalonServiceController extends BaseController
{
    @Autowired
    private ISalonServiceService salonServiceService;

    /**
     * 查询服务管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalonService salonService)
    {
        startPage();
        List<SalonService> list = salonServiceService.selectSalonServiceList(salonService);
        return getDataTable(list);
    }

    /**
     * 导出服务管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:service:export')")
    @Log(title = "服务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalonService salonService)
    {
        List<SalonService> list = salonServiceService.selectSalonServiceList(salonService);
        ExcelUtil<SalonService> util = new ExcelUtil<SalonService>(SalonService.class);
        util.exportExcel(response, list, "服务管理数据");
    }

    /**
     * 获取服务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:service:query')")
    @GetMapping(value = "/{serviceId}")
    public AjaxResult getInfo(@PathVariable("serviceId") Integer serviceId)
    {
        return AjaxResult.success(salonServiceService.selectSalonServiceByServiceId(serviceId));
    }

    /**
     * 新增服务管理
     */
    @PreAuthorize("@ss.hasPermi('system:service:add')")
    @Log(title = "服务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalonService salonService)
    {
        return toAjax(salonServiceService.insertSalonService(salonService));
    }

    /**
     * 修改服务管理
     */
    @PreAuthorize("@ss.hasPermi('system:service:edit')")
    @Log(title = "服务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalonService salonService)
    {
        return toAjax(salonServiceService.updateSalonService(salonService));
    }

    /**
     * 删除服务管理
     */
    @PreAuthorize("@ss.hasPermi('system:service:remove')")
    @Log(title = "服务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serviceIds}")
    public AjaxResult remove(@PathVariable Integer[] serviceIds)
    {
        return toAjax(salonServiceService.deleteSalonServiceByServiceIds(serviceIds));
    }
}
